package agentspeakeditor.editors.codeassist;

import org.eclipse.jface.resource.ImageRegistry;
import org.eclipse.jface.text.DocumentEvent;
import org.eclipse.jface.text.IDocument;
import org.eclipse.jface.text.ITextViewer;
import org.eclipse.jface.text.contentassist.ICompletionProposal;
import org.eclipse.jface.text.contentassist.ICompletionProposalExtension2;
import org.eclipse.jface.text.contentassist.ICompletionProposalExtension4;
import org.eclipse.jface.text.contentassist.IContextInformation;
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.graphics.Point;
import org.eclipse.ui.plugin.AbstractUIPlugin;

import agentspeakeditor.Activator;
import agentspeakeditor.editors.common.ASLCommonUIPluginImages;

public class ASLContentProposal implements ICompletionProposal,
ICompletionProposalExtension2, ICompletionProposalExtension4,
Comparable<ASLContentProposal> {

private String display = null;
private String proposal = null;
private String insertionText = null;
ProposalType type = ProposalType.Unknown;

public ASLContentProposal (String proposal, ProposalType type){
	this.insertionText = proposal;
	this.type = type;
}

public ASLContentProposal (String proposal, String display , ProposalType type){
	this.insertionText = proposal;
	this.type = type;
	this.display = display;
}

@Override
public String getAdditionalProposalInfo() {
	
	String info = "";
	
	if(this.type == ProposalType.Plan){
		
		info = this.insertionText;
	}
	else
		info = null;

	return info;
}

@Override
public IContextInformation getContextInformation() {
return null;
}

@Override
public String getDisplayString() {
	String display = "";
	
	if(this.type == ProposalType.Plan){		
		display = this.display;
	}
	else if(this.type == ProposalType.InitDesire){	
		display = insertionText + " - Initial Desire";
	}
	else if(this.type == ProposalType.Belief){
		display = insertionText + " - Belief";
	}
	
	return display;
}

@Override
public Image getImage() {	
	AbstractUIPlugin plugin = Activator.getDefault();
	ImageRegistry imageRegistry = plugin.getImageRegistry();
	Image myImage = null;
	
	if(type == ProposalType.Plan)
		myImage = imageRegistry.get(ASLCommonUIPluginImages.ID_PLAN);
	else if (type == ProposalType.InitDesire)
		myImage = imageRegistry.get(ASLCommonUIPluginImages.ID_DESIRE);
	else if (type == ProposalType.Belief)
		myImage = imageRegistry.get(ASLCommonUIPluginImages.ID_BELIEF);
	
	
	return myImage;
}

@Override
public Point getSelection(IDocument document) {
	return null;
}

@Override
public void selected(ITextViewer viewer, boolean smartToggle) {
}

@Override
public void unselected(ITextViewer viewer) {
}

@Override
public boolean validate(IDocument document, int offset, DocumentEvent event) {
	return false;
}

@Override
public boolean isAutoInsertable() {
return false;
}

public void setDisplayString(String displayStr)
{
this.proposal = displayStr;
}

public String getInsertionText() {
return insertionText;
}

public void setInsertionText(String insertionText) {
this.insertionText = insertionText;
}

@Override
public int compareTo(ASLContentProposal o) {
	// TODO Auto-generated method stub
	return 0;
}

@Override
public void apply(IDocument document) {
	// TODO Auto-generated method stub
	
}

@Override
public void apply(ITextViewer viewer, char trigger, int stateMask, int offset) {
	// TODO Auto-generated method stub
	
}

public enum ProposalType {
	
	Unknown,
	InitDesire,
	Plan,
	Command,
	Belief

}

}